package com.team1.system.librarytag.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.team1.common.annotation.Log;
import com.team1.common.core.controller.BaseController;
import com.team1.common.core.domain.AjaxResult;
import com.team1.common.enums.BusinessType;
import com.team1.system.librarytag.domain.LibraryTag;
import com.team1.system.librarytag.service.ILibraryTagService;
import com.team1.common.utils.poi.ExcelUtil;
import com.team1.common.core.page.TableDataInfo;

/**
 * 图书种类管理Controller
 * 
 * @author hyy
 * @date 2023-04-10
 */
@RestController
@RequestMapping("/librarysystem/librarytag")
public class LibraryTagController extends BaseController
{
    @Autowired
    private ILibraryTagService libraryTagService;

    /**
     * 查询图书种类管理列表
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarytag:list')")
    @GetMapping("/list")
    public TableDataInfo list(LibraryTag libraryTag)
    {
        startPage();
        List<LibraryTag> list = libraryTagService.selectLibraryTagList(libraryTag);
        return getDataTable(list);
    }

    /**
     * 导出图书种类管理列表
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarytag:export')")
    @Log(title = "图书种类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LibraryTag libraryTag)
    {
        List<LibraryTag> list = libraryTagService.selectLibraryTagList(libraryTag);
        ExcelUtil<LibraryTag> util = new ExcelUtil<LibraryTag>(LibraryTag.class);
        util.exportExcel(response, list, "图书种类管理数据");
    }

    /**
     * 获取图书种类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarytag:query')")
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId)
    {
        return success(libraryTagService.selectLibraryTagByTagId(tagId));
    }

    /**
     * 新增图书种类管理
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarytag:add')")
    @Log(title = "图书种类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LibraryTag libraryTag)
    {
        return toAjax(libraryTagService.insertLibraryTag(libraryTag));
    }

    /**
     * 修改图书种类管理
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarytag:edit')")
    @Log(title = "图书种类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LibraryTag libraryTag)
    {
        return toAjax(libraryTagService.updateLibraryTag(libraryTag));
    }

    /**
     * 删除图书种类管理
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarytag:remove')")
    @Log(title = "图书种类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagIds}")
    public AjaxResult remove(@PathVariable Long[] tagIds)
    {
        return toAjax(libraryTagService.deleteLibraryTagByTagIds(tagIds));
    }
}
